/**
 * auth: zhukaijun
 * date: 2022-7-22
 * des: data handler
 */
//过滤对象空值
export function filterObj(obj) {
    let result = {}
    for (let key of Object.keys(obj)) {
        if (obj[key] === "") {

        } else {
            Object.assign(result, {
                [key]: obj[key]
            });
        }
    }
    return result;
}
//用另一个对象的值覆盖此对象的值切不新增字段
export function coverObj(obj, data) {
    let result = {}
    Object.keys(obj).forEach(key => {
        result[key] = data[key]
    })
    return result
} //判断两个对象的值是否相等
export function objEqual(a, b) {
    if (Object.keys(a).length !== Object.keys(b).length) {
        return false
    }
    for (let key in a) {
        if (b[key] === undefined) {
            return false
        }
        if (typeof(b[key]) === 'function' || typeof(a[key]) === 'function') {
            throw new Error('type error')
        }
        if (typeof(b[key]) != typeof(a[key])) {
            return false
        }
        if (typeof(a[key]) === 'object') {
            return objEqual(a[key], b[key])
        }
        if (a[key] !== b[key]) {
            return false
        }
    }
    return true
}
export function ObjectHaveEmptyValue(obj) {
    // debugger
    let flag = false;
    Object.values(obj).forEach((item, index) => {
        if (item === '' || item === undefined) {
            flag = true
        }
    })
    return flag;
}
//验证手机号
export function checkPhone(phone) {
    // debugger
    let myReg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
    return myReg.test(phone);
}
//验证邮箱号
export function checkEmail(email) {
    // debugger
    let myReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    return myReg.test(email);
}

export function checkCaseNumber(value) {
    // debugger
    let myReg = /^[A-Za-z]{4}[0-9]{7}$/;
    return myReg.test(value);
}
// export function Sstr
//数字限制两位小数
export function toFixed2(value) {
    return value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
}
//只能输入正整数
export function positiveInteger(value) {
    return value.replace(/^(0+)|[^\d]+/g, '')
}
//只能输入汉字数字字母
export function positiveInputName(value) {
    let myReg = /^[A-Za-z0-9\u4e00-\u9fa5]+$/;
    return myReg.test(value);
}
export function dealProcessData(data) {
    let array = [];
    data.forEach((item, index) => {
        let obj = {};
        Object.assign(obj, item)
        if (item.status === 'FINISH') {
            Object.assign(obj, { typeNumber: 1 }); //已完成
        } else if (item.status === 'UNFINISHED') {
            if (item.presetTime) {
                Object.assign(obj, { typeNumber: 2 }); //有预设时间
            } else {
                Object.assign(obj, { typeNumber: 3 }); //无预设时间
            }
        } else if (item.status === 'NOTNEEDFINISHED') {
            Object.assign(obj, { typeNumber: 4 }); //无需完成
        }
        array.push(obj);
    })
    return array
}
//根据对象数组中某个值去重
export function unique(arr1, keyName) {
    const res = new Map();
    return arr1.filter((a) => !res.has(a[keyName]) && res.set(a[keyName], 1))
}